// 简单的vConsole替代方案
class SimpleConsole {
	constructor() {
		this.logs = [];
		this.isVisible = false;
		this.init();
	}
	
	init() {
		// 只在H5环境下启用
		// #ifdef H5
		this.createConsoleButton();
		this.createConsolePanel();
		this.interceptConsole();
		// #endif
	}
	
	createConsoleButton() {
		const button = document.createElement('div');
		button.innerHTML = '🔧';
		button.style.cssText = `
			position: fixed;
			bottom: 20px;
			right: 20px;
			width: 50px;
			height: 50px;
			background: #00d4aa;
			color: white;
			border-radius: 50%;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 20px;
			cursor: pointer;
			z-index: 10000;
			box-shadow: 0 2px 10px rgba(0,0,0,0.3);
		`;
		
		button.onclick = () => this.toggle();
		document.body.appendChild(button);
	}
	
	createConsolePanel() {
		const panel = document.createElement('div');
		panel.id = 'simple-console';
		panel.style.cssText = `
			position: fixed;
			bottom: 0;
			left: 0;
			right: 0;
			height: 300px;
			background: #1e1e1e;
			color: #fff;
			font-family: monospace;
			font-size: 12px;
			overflow-y: auto;
			padding: 10px;
			display: none;
			z-index: 9999;
			border-top: 2px solid #00d4aa;
		`;
		
		document.body.appendChild(panel);
		this.panel = panel;
	}
	
	interceptConsole() {
		const originalLog = console.log;
		const originalError = console.error;
		const originalWarn = console.warn;
		
		console.log = (...args) => {
			originalLog.apply(console, args);
			this.addLog('LOG', args.join(' '), '#fff');
		};
		
		console.error = (...args) => {
			originalError.apply(console, args);
			this.addLog('ERROR', args.join(' '), '#ff6b6b');
		};
		
		console.warn = (...args) => {
			originalWarn.apply(console, args);
			this.addLog('WARN', args.join(' '), '#ffd93d');
		};
	}
	
	addLog(type, message, color) {
		const time = new Date().toLocaleTimeString();
		const logElement = document.createElement('div');
		logElement.style.cssText = `
			margin-bottom: 5px;
			padding: 2px 0;
			border-bottom: 1px solid #333;
		`;
		logElement.innerHTML = `
			<span style="color: #888">[${time}]</span>
			<span style="color: ${color}; font-weight: bold">[${type}]</span>
			<span style="color: ${color}">${message}</span>
		`;
		
		if (this.panel) {
			this.panel.appendChild(logElement);
			this.panel.scrollTop = this.panel.scrollHeight;
		}
	}
	
	toggle() {
		this.isVisible = !this.isVisible;
		if (this.panel) {
			this.panel.style.display = this.isVisible ? 'block' : 'none';
		}
	}
	
	clear() {
		if (this.panel) {
			this.panel.innerHTML = '';
		}
	}
}

// 自动初始化
// #ifdef H5
if (typeof window !== 'undefined') {
	window.addEventListener('DOMContentLoaded', () => {
		window.simpleConsole = new SimpleConsole();
	});
}
// #endif

export default SimpleConsole;